//
//  HZL_StoryItemCollectionViewCell.m
//  B_Project
//
//  Created by 胡佳俊 on 15/11/28.
//  Copyright © 2015年 HZL. All rights reserved.
//

#import "HZL_StoryItemCollectionViewCell.h"

@interface HZL_StoryItemCollectionViewCell ()
@property (nonatomic, retain)UIImageView *coverImg;
@property (nonatomic, retain)UILabel *titleLable;
@property (nonatomic, retain)UIImageView *photoImg;
@property (nonatomic, retain)UILabel *nameLable;
@property (nonatomic, retain)UILabel *location;
@property (nonatomic, retain)UIImageView *img; //阴影

@end
@implementation HZL_StoryItemCollectionViewCell
#pragma mark - 初始化
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.coverImg = [[UIImageView alloc]init];
        [self.contentView addSubview:self.coverImg];
        self.coverImg.contentMode = UIViewContentModeScaleAspectFill;
        self.coverImg.clipsToBounds = YES;
     
        
        
        self.img = [[UIImageView alloc]init];
        [self.contentView addSubview:self.img];
        self.img.image = [UIImage imageNamed:@"jiabian2"];
        self.img.frame = CGRectMake(0, 0, (self.frame.size.width - 30) / 2, 150);
        [self.contentView addSubview:self.img];
        
        self.location = [[UILabel alloc]init];
        [self.coverImg addSubview:self.location];
        self.location.font = [UIFont fontWithName:@"Arial" size:11];
        
        //self.location.shadowColor = [UIColor blackColor];

        
        self.titleLable = [[UILabel alloc]init];
        self.titleLable.numberOfLines = 2;
        [self.contentView addSubview:self.titleLable];
        self.titleLable.textColor = [UIColor darkGrayColor];
        
        self.titleLable.font = [UIFont systemFontOfSize:12];

        
        self.photoImg = [[UIImageView alloc]init];
        self.photoImg.backgroundColor = [UIColor colorWithRed:0.98 green:0.97 blue:0.93 alpha:1];
        
        [self.contentView addSubview:self.photoImg];

        
        self.nameLable = [[UILabel alloc]init];
        self.nameLable.font = [UIFont systemFontOfSize:10];
        
        self.nameLable.textColor = [UIColor darkGrayColor];
        [self.contentView addSubview:self.nameLable];

        
        
    }
    return self;
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    [super applyLayoutAttributes:layoutAttributes];
    
    self.coverImg.frame = CGRectMake(0, 0, layoutAttributes.size.width, 150);
    self.location.frame = CGRectMake(10, self.coverImg.frame.size.height - 10 - 15, self.coverImg.frame.size.width - 20, 15);
    self.titleLable.frame = CGRectMake(10, self.coverImg.frame.size.height + 15, self.coverImg.frame.size.width - 20, 30);
    self.photoImg.frame = CGRectMake(10, self.titleLable.frame.origin.y + self.titleLable.frame.size.height + 15,25 , 25);
    self.photoImg.layer.masksToBounds = YES;
    self.photoImg.layer.cornerRadius = self.photoImg.frame.size.width / 2;
    self.nameLable.frame = CGRectMake(10 + 25 + 10, self.photoImg.frame.origin.y + 5, 100, 15);
    
    
        self.contentView.backgroundColor = [UIColor whiteColor];
        self.titleLable.textColor = [UIColor darkGrayColor];
        self.nameLable.textColor = [UIColor darkGrayColor];
        self.location.textColor = [UIColor whiteColor];
        self.coverImg.backgroundColor = [UIColor whiteColor];
  
}


#pragma mark - 首页故事赋值
- (void)setRecommendModel:(HZL_RecommendModel *)recommendModel
{
    if (_recommendModel != recommendModel) {
        _recommendModel = recommendModel;
    }
    [self.coverImg sd_setImageWithURL:[NSURL URLWithString:recommendModel.index_cover] placeholderImage:[UIImage sd_animatedGIFNamed:@"load"]];
    self.titleLable.text = recommendModel.index_title;
    self.location.text = recommendModel.poiName;
}

- (void)setUserModel:(HZL_RecommendModel *)userModel
{
    if (_userModel != userModel) {
        _userModel = userModel;
    }
    [self.photoImg sd_setImageWithURL:[NSURL URLWithString:userModel.avatar_m] placeholderImage:nil];
    self.nameLable.text = userModel.name;
    
}

#pragma mark - 全部页赋值
- (void)setStoryAllModel:(HZL_RecommendModel *)storyAllModel
{
    if (_storyAllModel != storyAllModel) {
        _storyAllModel = storyAllModel;
    }
    [self.coverImg sd_setImageWithURL:[NSURL URLWithString:storyAllModel.index_cover] placeholderImage:[UIImage sd_animatedGIFNamed:@"load"]];
    self.titleLable.text = storyAllModel.index_title;
    self.location.text = storyAllModel.poiName;
}
- (void)setStoryUserModel:(HZL_RecommendModel *)storyUserModel
{
    if (_storyUserModel != storyUserModel) {
        _storyUserModel = storyUserModel;
    }
    [self.photoImg sd_setImageWithURL:[NSURL URLWithString:storyUserModel.index_cover] placeholderImage:nil];
    self.nameLable.text = storyUserModel.name;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
